home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / SATminimal demo ƒ / sMySprite.p < prev   
Text File  |  1995-01-15  |  2KB  |  62 lines

  1. {The sprite unit for SATminimal}
  2.  
  3. unit sMySprite;
  4.  
  5. interface
  6.     uses
  7. {$ifc UNDEFINED THINK_PASCAL}
  8.         Types, QuickDraw, {}
  9. {$endc}
  10.         SAT;
  11.     var
  12.         theSound: Handle;
  13.         faces: array[0..5] of FacePtr;
  14.  
  15.     procedure InitMySprite;
  16.     procedure SetupMySprite (me: SpritePtr);
  17.     procedure HandleMySprite (me: SpritePtr);
  18.  
  19. implementation
  20.  
  21. {Initialization of variables used by the sprite unit}
  22.     procedure InitMySprite;
  23.         var
  24.             i: integer;
  25.     begin
  26. {Preload the sound}
  27.         theSound := SATGetSound(128);
  28. {Preload all icons used by the sprites - 6 of them}
  29.         for i := 0 to 5 do
  30.             faces[i] := SATGetFace(128 + i);
  31.     end;
  32.  
  33. {Initialize a new sprite}
  34.     procedure SetupMySprite (me: SpritePtr);
  35.     begin
  36.         me^.mode := 0;                    {Pick a valid face number}
  37.         me^.speed.h := 2;                    {Set the speed - only horizontal is used here }
  38.         me^.task := @HandleMySprite;    {Set a handling routine. MANDATORY! If nil, the sprite will self-destruct.}
  39.     end;
  40.  
  41. {Define the behaviour of a sprite}
  42.     procedure HandleMySprite (me: SpritePtr);
  43.     begin
  44. {Select a face. We use me^.mode as face counter, rotating through them.}
  45.         me^.mode := (me^.mode + 1) mod 6;
  46.         me^.face := faces[me^.mode];
  47.  
  48. {Move}
  49.         me^.position.h := me^.position.h + me^.speed.h; {Add the speed - horizontal only}
  50.         if me^.position.h > gSAT.offSizeH - 16 then {Turn back if at the right border}
  51.             begin
  52.                 me^.speed.h := -2;
  53.                 SATSoundPlay(theSound, 1, true);
  54.             end;
  55.         if me^.position.h < -16 then {Turn back if at the left border}
  56.             begin
  57.                 me^.speed.h := 2;
  58.                 SATSoundPlay(theSound, 1, true);
  59.             end;
  60.     end;
  61.  
  62. end.